package com.shop.admin.controller;

import com.shop.admin.entity.WechatModule;
import com.shop.admin.result.ApiResult;
import com.shop.admin.service.WechatModuleService;
import com.shop.admin.utils.PageUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;

@Api(tags = {"WechatModuleController"},description = "微信小程序模块接口")
@RestController
@RequestMapping("/api/module")
public class WechatModuleController {

    @Resource
    private WechatModuleService wechatModuleService;

    @GetMapping("/list")
    @ApiOperation(value = "模块列表",notes = "page,limit,orgId")
    public ApiResult list(@ApiParam("参数为：page,limit,组织id")@RequestParam Map<String, Object> params){
        PageUtils page = wechatModuleService.queryPage(params);
        return ApiResult.ok(page);
    }

    @PostMapping("/update")
    @ApiOperation(value = "模块新增or修改",notes = "id,图片路径，跳转路径，模块名字，显示狀態（0->不显示，1->正常），组织id,")
    public ApiResult updateOrSaveWechatModule(@ApiParam("参数为：id,moduleImg,modulePath,moduleName,status,orgId")@RequestBody WechatModule WechatModule){
        wechatModuleService.updateOrSaveWechatModule(WechatModule);
        return ApiResult.ok("操作成功！");
    }

    /**
     * 轮播图删除
     */
    @PostMapping("/delete")
    @ApiOperation(value = "模块删除",notes = "id数组")
    public ApiResult delete(@ApiParam("参数为：Id[]")@RequestBody Long[] ids){
        wechatModuleService.removeMenuByIds(Arrays.asList(ids));
        return ApiResult.ok("删除成功！");
    }
}
